package com.example.newsdaily.slice;

import com.example.newsdaily.*;
import com.example.newsdaily.utl.ContainUtil;
import com.example.newsdaily.utl.LocalDataUtil;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.components.Text;
import ohos.data.preferences.Preferences;

public class UserAbilitySlice extends AbilitySlice {
    Preferences preferences= LocalDataUtil.preferences;
    Button exitlog;
    Button changecode;
    Button developers;
    String user_name=LocalDataUtil.preferences.getString(ContainUtil.USER_NAME_KEY,"");
    Text name;
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_User);
        exitlog=(Button)findComponentById(ResourceTable.Id_exit_lg);
        changecode=(Button)findComponentById(ResourceTable.Id_user_rstps);
        developers=(Button)findComponentById(ResourceTable.Id_user_developer);
        name=(Text)findComponentById(ResourceTable.Id_user_name);
        name.setText(user_name);

        exitlog.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                preferences.putBoolean(ContainUtil.USER_REMEMBER_KEY,false);
                Intent intent1=new Intent();
                Operation operation=new Intent.OperationBuilder()
                        .withBundleName(getBundleName())
                        .withAbilityName(LoginAbility.class)
                        .build();
                intent1.setOperation(operation);
                startAbility(intent1);
            }
        });

        changecode.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                Intent intent=new Intent();
                Operation operation=new Intent.OperationBuilder()
                        .withBundleName(getBundleName())
                        .withAbilityName(ChangeCodeAbility.class)
                        .build();
                intent.setOperation(operation);
                startAbility(intent);
            }
        });

        developers.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                Intent intent=new Intent();
                Operation operation=new Intent.OperationBuilder()
                        .withBundleName(getBundleName())
                        .withAbilityName(DeveloperAbility.class)
                        .build();
                intent.setOperation(operation);
                startAbility(intent);
            }
        });

    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
